//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	IEntity.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using Smart.Common.Security;

namespace Smart.Common.Entities
{
	/// <summary>
	/// Entity base
	/// </summary>
	public interface IEntity : ICloneable, ISecurable
	{
		/// <summary>
		/// Source list, where entity is saved
		/// </summary>
		IEntityList List { get; set; }

		/// <summary>
		/// Data source item, will be null if cache used
		/// </summary>
		object Source { get; set; }

		/// <summary>
		/// true, if fields changed
		/// </summary>
		bool Changed { get; set; }

		/// <summary>
		/// Item ID
		/// </summary>
		Identifier ID { get; set; }

		/// <summary>
		/// Item Title
		/// </summary>
		string Title { get; set; }

		/// <summary>
		/// Return whether this entity is new
		/// </summary>
		bool IsNew { get; }

		/// <summary>
		/// Event handler
		/// </summary>
		void OnCreated();

		/// <summary>
		/// Event handler, data source saved in Source
		/// </summary>
		void OnLoading();

		/// <summary>
		/// Event handler, data source saved in Source
		/// </summary>
		void OnLoaded();

		/// <summary>
		/// Event handler, data source saved in Source
		/// </summary>
		void OnSaving();

		/// <summary>
		/// Event handler, data source saved in Source
		/// </summary>
		void OnSaved();

		/// <summary>
		/// Reload all properties from source (uses ISPEntityList)
		/// </summary>
		bool Reload();

		/// <summary>
		/// Save all properties to underlying system (uses ISPEntityList)
		/// </summary>
		/// <returns>true, if succeeded</returns>
		bool Save();

		/// <summary>
		/// Recycle item: move to recycle bin (uses ISPEntityList)
		/// </summary>
		/// <returns>true, if succeeded</returns>
		bool Recycle();

		/// <summary>
		/// Return item data source (loads if needed)
		/// </summary>
		object GetSource();
	}
}